//
//  Permissions.swift
//  OnemeetingDemo
//
//  Created by 张衡 on 2020/3/12.
//  Copyright © 2020 www.onemeeting.1meetingIos. All rights reserved.
//

import Foundation

class Permissions: NSObject {
    
    static let share = Permissions()
    
    class func canAccessibility() -> Bool {
        let options = [(kAXTrustedCheckOptionPrompt.takeRetainedValue() as String):false]
        let accessibilityEnabled = AXIsProcessTrustedWithOptions(options as CFDictionary)
        return accessibilityEnabled
    }
    
    class func openSetting_accessibility(){
        let urlString = "x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility"
        NSWorkspace.shared.open(URL.init(string: urlString)!)
    }
    
    //权限判断 ///tccutil reset All com.xx.xx
    class func canRecord() -> Bool {
        
        let displayID =  CGDirectDisplayID()
        let stream = CGDisplayStream.init(display: displayID, outputWidth: 1, outputHeight: 1, pixelFormat: Int32(kCVPixelFormatType_32ABGR), properties: nil, handler: nil)
        let canRecord:Bool = stream != nil
        if (stream != nil) {
            CGDisplayRelease(displayID)
        }
        
        return canRecord
    }
    
    
    class func showScreenRecordingPrompt() {
        guard #available(OSX 10.15, *) else {
            return
        }
        
        CGWindowListCreateImage(CGRect.init(x: 0, y: 0, width: 1, height: 1), CGWindowListOption.optionOnScreenOnly, CGWindowID.zero, CGWindowImageOption.boundsIgnoreFraming)
    }
    
    class func openSetting_screenCapture()  {
        let urlString = "x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture"
        NSWorkspace.shared.open(URL.init(string: urlString)!)
    }
}
